﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

using nr.GLV.Windows.Controls;

namespace nr.GLV.Windows
{
    public partial class GravesDatagrid : nr.GLV.Windows.Controls.ArchiveUserControl
    {
        public GravesDatagrid()
        {
            InitializeComponent();
            FilterFields.Clear();

            FilterFields.AddRange(
                new FilterField[]{
                    new FilterField("Nome Completo","GraveFullName"),
                    new FilterField("Contribuente", "CustomerFullName"),
                    new FilterField("Nome","FirstName"),
                    new FilterField("Cognome", "LastName"),
                    new FilterField("Data Nascita", "BirthDate", FieldType.Date),
                    new FilterField("Data Morte", "DeadDate", FieldType.Date)
                });
        }

        protected override void OnDataChanged(EventArgs e)
        {
            base.OnDataChanged(e);

            customersBindingSource.DataSource = Data;
            gravesBindingSource.DataSource = Data;
        }

        protected override void OnFilterReset(EventArgs e)
        {
            base.OnFilterReset(e);
            gravesBindingSource.RemoveFilter();
        }

        protected override void OnFilterApply(EventArgs e)
        {
            base.OnFilterApply(e);
            gravesBindingSource.Filter = GetFilters();
        }

        private void dgGraves_RowsAdded(object sender, DataGridViewRowsAddedEventArgs e)
        {
            OnRecordCountChanged(new RecordCountChangedEventArgs(Title, dgGraves.Rows.Count));
        }

        private void dgGraves_RowsRemoved(object sender, DataGridViewRowsRemovedEventArgs e)
        {
            OnRecordCountChanged(new RecordCountChangedEventArgs(Title, dgGraves.Rows.Count));
        }

        private void dgGraves_DataBindingComplete(object sender, DataGridViewBindingCompleteEventArgs e)
        {
            OnRecordCountChanged(new RecordCountChangedEventArgs(Title, dgGraves.Rows.Count));
        }
    }
}
